package com.yuexun.dhdoctor.module.registration.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.module.registration.adapter.RegistrationListAdapter;
import com.yuexun.dhdoctor.widget.EmptyLayout;
import com.yuexun.dhdoctor.widget.PullToRefresh.FooterLoadingLayout;
import com.yuexun.dhdoctor.widget.PullToRefresh.PullToRefreshBase;
import com.yuexun.dhdoctor.widget.PullToRefresh.PullToRefreshList;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2018/4/20 0020.
 */

public class Act_Registration_Main extends BaseKJActivity {

    @Bind(R.id.start_date)
    TextView startDate;
    @Bind(R.id.end_date)
    TextView endDate;
    @Bind(R.id.content_list)
    PullToRefreshList contentList;
    @Bind(R.id.empty_layout)
    EmptyLayout emptyLayout;

    private ListView mList;
    RegistrationListAdapter adapter;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_registration_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        startDate.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        endDate.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        listViewPreference();
    }

    /**
     * 初始化ListView样式
     */
    private void listViewPreference() {
        mList = contentList.getRefreshView();
        mList.setOverscrollFooter(null);
        mList.setOverscrollHeader(null);
        mList.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
        contentList.setPullLoadEnabled(false);//设置上拉刷新功能关闭
        ((FooterLoadingLayout) contentList.getFooterLoadingLayout())
                .setNoMoreDataText("已经是最新状态");

        List<String> strings = new ArrayList<>();
        strings.add("");
        strings.add("");
        adapter = new RegistrationListAdapter(mList, strings, R.layout.item_registration);
        mList.setAdapter(adapter);

//        adapter.setBackListener(new ICallBackListener() {
//            @Override
//            public void callback(Bundle bundle) {
//                Bundle bundle2 = new Bundle();
//                Intent intent = new Intent(aty, Act_Physical_Detail.class);
//                bundle2.putInt("type", 1);
//                intent.putExtras(bundle2);
//                startActivity(intent);
//            }
//        });

        emptyLayout.dismiss();

        mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
//                startActivity(new Intent(aty, Act_Doc_Detail.class));
            }
        });

        contentList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                contentList.setHasMoreData(false);
            }
        });

        emptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.title_back, R.id.start_date, R.id.end_date})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                break;
            case R.id.start_date:
                break;
            case R.id.end_date:
                break;
        }
    }
}
